#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 200010;
int f[N], w[N], q[N];
int n, m;
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> w[i];
    int hh = 0, tt = -1;
    for (int i = 0; i <= n; i++)
    {
        if (hh <= tt && q[hh] < i - m) hh++;
        if (i) f[i] = f[q[hh]] + w[i];
        while (hh <= tt && f[q[tt]] >= f[i]) tt--;
        q[++tt] = i;
    }
    int res = 2e9;
    for (int i = n - m + 1; i <= n; i++) res = min(res, f[i]);
    cout << res << endl;
    return 0;
}